@file:JvmName("AssetHandlerUtils") // 1️⃣

package com.starblink.basic.util;

import android.content.Context
import java.io.BufferedInputStream

/**
 * 读取assets中的【文本文件】内容
 */
fun <R> readText4Assets(ctx: Context, fileName: String, callback: (String?) -> R): R {
    var text: String? = null
    try {
        ctx.assets.open(fileName).use { ins ->
            BufferedInputStream(ins).use { bis ->
                text = bis.reader().readText()
            }
        }
    } finally {
        return callback(text)
    }
}

